var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var UI_GameOver_UIBindings = require("AA_UI_GameOver_UIBindings");
var UIView = require("AA_UIView");
var GameDataManager = require("AA_GameDataManager");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var Excel = require("AA_Excel");
var HallGlobalVariable = require("AA_HallGlobalVariable");
var Const_Hall = require("AA_Const_Hall");
var UI_GameOverItem = require("AA_UI_GameOverItem");
var LogManager = require("AA_LogManager");
var PlayerDataManager = require("AA_PlayerDataManager");
var Const_Common = require("AA_Const_Common");
var Const_Game = require("AA_Const_Game");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var AudioManager = require("AA_AudioManager");
var BundleConfig = require("AA_BundleConfig");
var AIControl = require("AA_AIControl");
var CommonUtils = require("AA_CommonUtils");
var TTAPI = require("AA_TTAPI");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_GameOver = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.nowdata = {};
    t.nowlevel = 1;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype._show = function (e) {
    var t = [];
    for (var o = 1; o < arguments.length; o++) {
      t[o - 1] = arguments[o];
    }
    this.nowdata = e;
    this.nowlevel = GameGlobalVariable.GameGlobalVariable.nowlevel;
    this.auto_ui.btn_fenxiang.node.active = true;
    if (1 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
      this.auto_ui.btn_fenxiang.node.active = false;
      this.nowlevel = GameGlobalVariable.GameGlobalVariable.teshulevel;
      PlayerDataManager.PlayerDataMgr.subWuJinCount(1);
    }
    if (1 == this.nowdata.type) {
      this.auto_ui.node_successtop.active = false;
      this.auto_ui.node_failtop.active = true;
      this.scaleNode(this.auto_ui.node_failtop);
      var n = GameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, GameGlobalVariable.GameGlobalVariable.isTeShuLevel());
      this.auto_ui.txt_nowboshu.string = "最高进度:第" + n + "波";
      AudioManager.AudioMgr.playEffect("game/sound/失败", false, BundleConfig.BundleNames.Game);
    } else {
      AudioManager.AudioMgr.playEffect("game/sound/胜利", false, BundleConfig.BundleNames.Game);
      this.auto_ui.node_successtop.active = true;
      this.scaleNode(this.auto_ui.node_successtop);
      this.auto_ui.node_failtop.active = false;
    }
    if (1 == GameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
      this.initTiaoZhanAward();
    } else {
      this.initAward();
    }
    this.AICheck();
    GameDataManager.GameDataMgr.updateCiTiao(this.nowlevel, null);
    CommonUtils.default.cleanGold();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_HIDE_CLICK);
  };
  _creator.prototype.scaleNode = function (e) {
    this.scheduleOnce(function () {
      e.scale = 0;
      cc.tween(e).to(.3, {
        scale: 1
      }, {
        easing: "backOut"
      }).start();
    });
  };
  _creator.prototype.initTiaoZhanAward = function () {
    var e = 100 * GameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, 1);
    this.itemData = new Const_Hall.GetItemsData();
    this.itemData.ids = [];
    this.itemData.counts = [];
    this.itemData.ids.push(12345);
    this.itemData.counts.push(e);
    this.initAwardUi(this.itemData);
  };
  _creator.prototype.initAward = function () {
    var e = this;
    var t = Excel.Excel.shuiguoguanqia(this.nowlevel);
    var o = t.levelaward;
    var n = GameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, 2);
    var i = o[0][1];
    this.itemData = new Const_Hall.GetItemsData();
    this.itemData.ids = [];
    this.itemData.counts = [];
    GameGlobalVariable.GameGlobalVariable.isFirstGuide = false;
    if (PlayerDataManager.PlayerDataMgr.GetGuideIndexByTaskName(Const_Common.GuideName.仓库升级) == Const_Common.UpEquipLevelGuideIndex.给固定奖励1) {
      this.itemData.ids.push(HallGlobalVariable.default.goldId);
      this.itemData.counts.push(200);
      this.itemData.ids.push(Const_Game.FruitId.杨桃忍者);
      this.itemData.counts.push(4);
    } else {
      var a = Math.floor(n * (i / t.levelboshuid.length));
      if (a > 0) {
        this.itemData.ids.push(HallGlobalVariable.default.goldId);
        this.itemData.counts.push(a);
      }
      GameGlobalVariable.GameGlobalVariable.addjinbi = a;
      var r = function (e, o) {
        if (n < e) {
          return 0;
        } else {
          return Math.floor((n + 1 - e) / (t.levelboshuid.length + 1 - e) * o);
        }
      };
      var c = o[1];
      var s = r(t.awardboshuid[0], c[2]);
      LogManager.LogMgr.debug("绿色碎片数量", s);
      var f = o[2];
      var v = 0;
      if (f) {
        v = r(t.awardboshuid[1], f[2]);
        LogManager.LogMgr.debug("蓝色碎片数量", v);
      }
      var b = o[3];
      var w = 0;
      if (b) {
        w = r(t.awardboshuid[2], b[2]);
        LogManager.LogMgr.debug("紫碎片数量", w);
      }
      HallGlobalVariable.default.GetSuiPian([s, v, w]).forEach(function (t, o) {
        e.itemData.ids.push(o);
        e.itemData.counts.push(t);
        PlayerDataManager.PlayerDataMgr.AddEquipFragments(o, t);
      });
    }
    this.initAwardUi(this.itemData);
    var I = GameDataManager.GameDataMgr.getNowMaxLevel();
    cc.sys.platform == cc.sys.BYTEDANCE_GAME && TTAPI.default.setImRankData(I);
  };
  _creator.prototype.getNodes = function (e) {
    var t = e.ids.length;
    var o = 1;
    if (t > 4) {
      var n = t % 4;
      o = (t - n) / 4;
      n > 0 && (o += 1);
    }
    var i = this.auto_ui.scroll_nowscroll.content.children;
    var a = [];
    var r = 0;
    for (var c = 0; c < i.length; c++) {
      var s = i[c];
      if (c < o) {
        s.active = true;
        s.children[0].children.forEach(function (t) {
          if (r < e.ids.length) {
            t.scale = 0;
            a.push(t);
            r++;
          } else {
            t.active = false;
          }
        });
      } else {
        s.active = false;
      }
    }
    return a;
  };
  _creator.prototype.initAwardUi = function (e) {
    var t = this.getNodes(e);
    var o = 0;
    this.schedule(function () {
      var n = t[o];
      var i = e.ids[o];
      var a = e.counts[o];
      n.getComponent(UI_GameOverItem.default).initUi(i, a);
      cc.tween(n).to(.3, {
        scale: 1
      }, {
        easing: "backOut"
      }).start();
      o += 1;
    }, .1, t.length - 1);
  };
  _creator.prototype._clickListener = function (e) {
    var t = this;
    var o = this.auto_ui;
    switch (e) {
      case o.btn_fenxiang:
        if (cc.sys.isBrowser) {
          var n = this.itemData.counts;
          for (var i = 0; i < n.length; i++) {
            var a = this.itemData.counts[i];
            this.itemData.counts[i] = 2 * a;
          }
          this.initAwardUi(this.itemData);
          this.auto_ui.btn_fenxiang.node.active = false;
        } else {
          CommonUtils.default.onshare(function (e) {
            if (e) {
              var o = t.itemData.counts;
              for (var n = 0; n < o.length; n++) {
                var i = t.itemData.counts[n];
                t.itemData.counts[n] = 2 * i;
              }
              t.initAwardUi(t.itemData);
              t.auto_ui.btn_fenxiang.node.active = false;
            }
          });
        }
        break;
      case o.btn_queding:
        this.GetReward(false);
        this.onBackHome();
    }
  };
  _creator.prototype.GetReward = function (e) {
    if (this.itemData) {
      for (var t = 0; t < this.itemData.ids.length; t++) {
        var o = this.itemData.ids[t];
        var n = this.itemData.counts[t];
        e && (n *= 2);
        switch (o) {
          case HallGlobalVariable.default.goldId:
            PlayerDataManager.PlayerDataMgr.AddGold(n);
            break;
          case 12345:
            var i = GameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, 1);
            GameDataManager.GameDataMgr.updateTiaoZhanFen(1, 100 * i);
            break;
          default:
            PlayerDataManager.PlayerDataMgr.AddEquipFragments(o, n);
        }
      }
      PlayerDataManager.PlayerDataMgr.GetGuideIndexByTaskName(Const_Common.GuideName.仓库升级) == Const_Common.UpEquipLevelGuideIndex.给固定奖励1 && PlayerDataManager.PlayerDataMgr.SetGuideIndex(Const_Common.GuideName.仓库升级, Const_Common.UpEquipLevelGuideIndex.引导点击仓库水果2);
    }
  };
  _creator.prototype.onBackHome = function () {
    this.nowdata.back(2);
    this.onCloseView();
  };
  _creator.prototype.onBack = function () {
    this.nowdata.back(2);
    this.onCloseView();
  };
  _creator.prototype.onCloseView = function () {
    this._close();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Value_Fei);
  };
  _creator.prototype.AICheck = function () {
    var e = this;
    AIControl.default._instance.isOpen && this.scheduleOnce(function () {
      AIControl.default._instance.ShowClickBtn(e.auto_ui.btn_queding.node, function () {
        e.GetReward(false);
        e.onBackHome();
      });
    }, 1);
  };
  __decorate([_property(UI_GameOver_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  return __decorate([_ccclass], _creator);
}(UIView.default);
exports.default = _def_UI_GameOver;